package me.yuxiaoyao.example.lock.service.impl;

import me.yuxiaoyao.example.lock.service.TestService;
import me.yuxiaoyao.lock.annotation.DistributedLock;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * @author kerryzhang on 2020/12/22
 */


@Service
public class TestServiceImpl implements TestService {

    @DistributedLock(value = "#id")
    @Override
    public Object param(Long id) throws InterruptedException {
        Thread.sleep(5 * 1000L);
        return Collections.singletonMap("param", id);
    }

    @DistributedLock(value = "#methodName")
    @Override
    public Object method() throws InterruptedException {
        Thread.sleep(5 * 1000L);
        return Collections.singletonMap("method", "me.yuxiaoyao.example.lock.controller.TestController.method." + Thread.currentThread().getName());
    }

    @DistributedLock(value = "'constKey'")
    @Override
    public Object constKey() throws InterruptedException {
        Thread.sleep(5 * 1000L);
        return Collections.singletonMap("constKey", "constKey." + Thread.currentThread().getName());
    }

    @DistributedLock(value = "#id + ':constKey'")
    @Override
    public Object mixParam(Long id) throws InterruptedException {
        Thread.sleep(5 * 1000L);
        return Collections.singletonMap("mixParam", id + ":constKey." + Thread.currentThread().getName());
    }
}
